import junit.framework.TestCase;

public class SetTest extends TestCase {
	public void testConstructor ( ) {
		Set s = new Set (2);
		assertTrue (s.isEmpty());
		assertFalse (s.member(0));
		assertFalse (s.member(1));
	}
	
	public void testInsert ( ) {
		Set s = new Set (2);
		s.insert(0);
		assertFalse (s.isEmpty());
		assertTrue (s.member(0));
		assertFalse (s.member(1));
		s.insert(0); // should have no effect
		assertFalse (s.isEmpty());
		assertTrue (s.member(0));
		assertFalse (s.member(1));
	}
	
	public void testRemove ( ) {
		Set s = new Set (2);
		s.insert(0);
		s.remove(1);
		assertFalse (s.isEmpty());
		assertTrue (s.member(0));
		assertFalse (s.member(1));
		s.remove(0);
		assertTrue (s.isEmpty());
		assertFalse (s.member(0));
		assertFalse (s.member(1));
		s.remove(0); // should have no effect
		assertTrue (s.isEmpty());
		assertFalse (s.member(0));
		assertFalse (s.member(1));
	}
	
	
	
	public void testTwoInsertsAndRemoves ( ) {
		Set s = new Set (2);
		s.insert(0);
		s.insert(1);
		assertFalse (s.isEmpty());
		assertTrue (s.member(0));
		assertTrue (s.member(1));
		s.remove(1);
		assertFalse (s.isEmpty());
		assertTrue (s.member(0));
		assertFalse (s.member(1));
		s.remove(1); // should have no effect
		assertFalse (s.isEmpty());
		assertTrue (s.member(0));
		assertFalse (s.member(1));
		s.remove(0);
		assertTrue (s.isEmpty());
		assertFalse (s.member(0));
		assertFalse (s.member(1));
		s.remove(0); // should have no effect
		assertTrue (s.isEmpty());
		assertFalse (s.member(0));
		assertFalse (s.member(1));
	}

	
	
	public void testInitIterator(){
		Set s = new Set (5);
		s.checkFromHere = 10;
		s.initIterator();
		assertTrue(s.checkFromHere == 0);
	}
	public void testHasNext ( ) {		
		Set s = new Set (5);
		s.initIterator();
		assertTrue (!s.hasNext());
		s.setContains(new boolean[] {true,true,true,true});
		s.initIterator();
		assertTrue (s.hasNext());
		s.setContains(new boolean[] {false,false,false,true});
		s.initIterator();
		assertTrue (s.hasNext());
		s.setContains(new boolean[] {true,false,false,false});
		s.initIterator();
		assertTrue (s.hasNext());
	}
	/* test basic functionality;corner cases.*/
	public void testNext(){
		Set s = new Set (5);
		s.initIterator();
		assertTrue (s.next()==-1);
		s.setContains(new boolean[] {true,true,true,true});
		s.initIterator();
		assertTrue (s.next()==0);
		s.setContains(new boolean[] {false,false,false,true});
		s.initIterator();
		assertTrue (s.next()==3);
		s.setContains(new boolean[] {true,false,false,false});
		s.initIterator();
		assertTrue (s.next()==0);
		s.setContains(new boolean[] {false,false,true,false,false,false});
		s.initIterator();
		assertTrue (s.next()==2);
		
	}

}
